<template>
  <div>
    <el-dialog v-bind="dialogProps" :before-close="handleClose" :close-on-click-modal="false"
               :destroy-on-close="true" v-dialogDrag append-to-body>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm"
               size="small" :disabled="isDisabled">
        <el-row :gutter="16" justify="start" v-show="formShow">
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="单位名称" prop="unitName">
              <el-input v-model="ruleForm.unitName" placeholder="请输入单位名称" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="数据来源" prop="taskSourceName">
              <el-input v-model="ruleForm.taskSourceName" placeholder="请输入数据来源" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="缺陷名称" prop="defectName">
              <el-input v-model="ruleForm.defectName" placeholder="请输入缺陷名称" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="任务名称" prop="taskName">
              <el-input v-model="ruleForm.taskName" placeholder="请输入任务名称" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
              <el-form-item label="出厂编码" prop="ccbm">
                  <el-input v-model="ruleForm.ccbm" placeholder="请输入出厂编码" clearable disabled></el-input>
              </el-form-item>
          </el-col> -->
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="设备类型" prop="equipTypeName">
              <el-input v-model="ruleForm.equipTypeName" placeholder="请输入设备类型" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="设备名称" prop="equipName">
              <el-input v-model="ruleForm.equipName" placeholder="请输入设备名称" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="发现人" prop="creator">
              <el-input v-model="ruleForm.creator" placeholder="请输入发现人" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="发现日期" prop="creatTime">
              <el-input v-model="ruleForm.creatTime" placeholder="请输入发现日期" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="缺陷部位" prop="defectParts">
              <el-input v-model="ruleForm.defectParts" placeholder="请输入缺陷部位" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="缺陷地点" prop="defectAddress">
              <el-input v-model="ruleForm.defectAddress" placeholder="请输入缺陷地点" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="详细描述" prop="defectDescription">
              <el-input v-model="ruleForm.defectDescription" placeholder="请输入详细描述" clearable disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="是否现场处理" prop="isHandle">
              <el-select v-model="ruleForm.isHandle" placeholder="请选择" clearable style="width: 100%"
                         disabled
              >
                <el-option label="是" :value="'1'"></el-option>
                <el-option label="否" :value="'0'"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="处理状态" prop="defectStatusName">
              <el-input v-model="ruleForm.defectStatusName" placeholder="请输入处理状态" clearable disabled></el-input>
            </el-form-item>
          </el-col>

          <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
            <el-form-item label="处理日期" prop="qxyhXqsj">
              <el-input v-model="ruleForm.qxyhXqsj" placeholder="请输入处理日期" clearable disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {baseInfoFrom} from "../model/baseInfoFrom";
import {CommonApi} from '@/api/equip/CommonApi'
import {defectTaskApi} from "@/api/defects/defectTaskApi";
import {reactive} from "vue";
// import {warehouseManagement} from '@/api/warehouseManagement.js'
export default {
  data() {
    return {
      dialogProps: {
        visible: false,
        title: "信息详情",
        width: "70%",
        top: "5px",
      },
      footerVisible: true,
      size: "medium",
      ruleForm: reactive(baseInfoFrom).FormData,
      rules: reactive(baseInfoFrom).rules,
      disabledForm: true,
      zxoptions: [],
      sskfOptions: [],
      xsnrShow: true,
      row: {},
      classFont: 'fa fa-caret-down',
      formShow: true,
      isDisabled: false,
    };
  },
  methods: {
    showDialog(isEdit, row, isDisabled) {
      this.isDisabled = isDisabled
      console.log(isEdit, row, isDisabled, 1111);
      this.initData(row.row);
      this.dialogProps.visible = true;
      this.getOptionData_gldw()
    },
    basicsShow() {

      if (this.formShow) {
        this.formShow = false
        this.classFont = 'fa fa-caret-right'

      } else {
        this.formShow = true
        this.classFont = 'fa fa-caret-down'

      }

    },

    //选择设备弹窗
    equipmentModel() {
      this.$refs.selectEquipment.showDialog()

    },


    //编辑渲染
    initData(data) {
      console.log(data)
      for (let key in this.ruleForm) {
        this.ruleForm[key] = data[key];
      }
    },

    //确定
    handleSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.ruleForm.djshzt = '100'
          this.ruleForm.djshztmc = '通过'
          defectTaskApi.updateDjsh(this.ruleForm).then(res => {
            this.dialogProps.visible = false;
            this.$emit("closeShEvent");
          })
        } else {
          return false;
        }
      });

    },
    //取消
    handleCancel() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.list = {
            data: [],
          }
          this.row = {}
          this.ruleForm.djshzt = '20'
          this.ruleForm.djshztmc = '不通过'
          defectTaskApi.updateDjsh(this.ruleForm).then(res => {
            this.dialogProps.visible = false;
            this.$emit("closeShEvent");
          })
        } else {
          return false;
        }
      });
    },
    //确定关闭
    handleClose(done) {
      // this.$confirm("确认关闭？")
      //     .then((_) => {
      this.handleCancel()
      this.dialogProps.visible = false;
      // })
      // .catch((_) => { });
    },
    getOptionData_gldw() {//获取管理单位：字典表
      CommonApi.queryDictData('EN_EQUIP_GLDW').then(res => {
        // 修改编辑框
        // const sexColumn = $grid.getColumnByField('sex')
        // sexColumn.editRender.options = sexList
        // 修改查询条件列表
        let optionList = [
          {label: '请选择', value: ''}
        ]
        res.data.forEach((item) => {
          // console.log(item,'item.,,,');
          optionList.push({label: item.value, value: item.code})
        })
        this.zxoptions = optionList
      }).catch(err => {
        console.log(err)
      })
    }
  },
};

</script>
<style>
.el-dialog__footer {
  width: 100%;
  border-top: 1px solid #e8e8e8;
}
</style>
